import $web3js from "../web3.js";

const peTimeLockContract = require("./peTimeLock.json");

let contractAddress = "";
let web3 = $web3js.getWeb3();
let contractConst = {
  contract: web3
    ? new web3.eth.Contract(peTimeLockContract.abi, contractAddress)
    : ""
};
const getPeTimeLockAddress = () => {
  return contractAddress;
};

const getPeTimeLockContract = () => {
  return contractConst.contract;
};

const getCalcPERecvLock = () => {
  return $web3js.commonCallAndHandler(
    getPeTimeLockContract().methods.calcPERecvLock,
    $web3js.fromWei
  );
};

const peRecvLock = async () => {
  return $web3js.commonSend(getPeTimeLockContract().methods.peRecvLock);
};

const peRecvLockEstimateGas = async () => {
  return $web3js.commonEstimateGas(getPeTimeLockContract().methods.peRecvLock);
};

export default {
  getPeTimeLockAddress,
  getPeTimeLockContract,
  getCalcPERecvLock,
  peRecvLock,
  peRecvLockEstimateGas
};
